; RUN: clspv-opt -ReplaceOpenCLBuiltin %s -o %t
; RUN: FileCheck %s < %t

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

define spir_func void @test(i32 addrspace(1)* %gu, i32 addrspace(1)* %gs, i32 addrspace(3)* %lu, i32 addrspace(3)* %ls) {
entry:
  %call = tail call spir_func i32 @_Z10atomic_incPU3AS1Vj(i32 addrspace(1)* %gu)
  %call1 = tail call spir_func i32 @_Z10atomic_incPU3AS3Vj(i32 addrspace(3)* %lu)
  %call2 = tail call spir_func i32 @_Z10atomic_incPU3AS1Vi(i32 addrspace(1)* %gs)
  %call3 = tail call spir_func i32 @_Z10atomic_incPU3AS3Vi(i32 addrspace(3)* %ls)
  %call4 = tail call spir_func i32 @_Z8atom_incPU3AS1Vj(i32 addrspace(1)* %gu)
  %call5 = tail call spir_func i32 @_Z8atom_incPU3AS3Vj(i32 addrspace(3)* %lu)
  %call6 = tail call spir_func i32 @_Z8atom_incPU3AS1Vi(i32 addrspace(1)* %gs)
  %call7 = tail call spir_func i32 @_Z8atom_incPU3AS3Vi(i32 addrspace(3)* %ls)
  %call8 = tail call spir_func i32 @_Z10atomic_decPU3AS1Vj(i32 addrspace(1)* %gu)
  %call9 = tail call spir_func i32 @_Z10atomic_decPU3AS3Vj(i32 addrspace(3)* %lu)
  %call10 = tail call spir_func i32 @_Z10atomic_decPU3AS1Vi(i32 addrspace(1)* %gs)
  %call11 = tail call spir_func i32 @_Z10atomic_decPU3AS3Vi(i32 addrspace(3)* %ls)
  %call12 = tail call spir_func i32 @_Z8atom_decPU3AS1Vj(i32 addrspace(1)* %gu)
  %call13 = tail call spir_func i32 @_Z8atom_decPU3AS3Vj(i32 addrspace(3)* %lu)
  %call14 = tail call spir_func i32 @_Z8atom_decPU3AS1Vi(i32 addrspace(1)* %gs)
  %call15 = tail call spir_func i32 @_Z8atom_decPU3AS3Vi(i32 addrspace(3)* %ls)
  %call16 = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS1Vjjj(i32 addrspace(1)* %gu, i32 7, i32 42)
  %call17 = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS3Vjjj(i32 addrspace(3)* %lu, i32 7, i32 42)
  %call18 = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS1Viii(i32 addrspace(1)* %gs, i32 7, i32 42)
  %call19 = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS3Viii(i32 addrspace(3)* %ls, i32 7, i32 42)
  %call20 = tail call spir_func i32 @_Z12atom_cmpxchgPU3AS1Vjjj(i32 addrspace(1)* %gu, i32 7, i32 42)
  %call21 = tail call spir_func i32 @_Z12atom_cmpxchgPU3AS3Vjjj(i32 addrspace(3)* %lu, i32 7, i32 42)
  %call22 = tail call spir_func i32 @_Z12atom_cmpxchgPU3AS1Viii(i32 addrspace(1)* %gs, i32 7, i32 42)
  %call23 = tail call spir_func i32 @_Z12atom_cmpxchgPU3AS3Viii(i32 addrspace(3)* %ls, i32 7, i32 42)
  ret void
}

declare spir_func i32 @_Z10atomic_incPU3AS1Vj(i32 addrspace(1)*)
declare spir_func i32 @_Z10atomic_incPU3AS3Vj(i32 addrspace(3)*)
declare spir_func i32 @_Z10atomic_incPU3AS1Vi(i32 addrspace(1)*)
declare spir_func i32 @_Z10atomic_incPU3AS3Vi(i32 addrspace(3)*)
declare spir_func i32 @_Z8atom_incPU3AS1Vj(i32 addrspace(1)*)
declare spir_func i32 @_Z8atom_incPU3AS3Vj(i32 addrspace(3)*)
declare spir_func i32 @_Z8atom_incPU3AS1Vi(i32 addrspace(1)*)
declare spir_func i32 @_Z8atom_incPU3AS3Vi(i32 addrspace(3)*)
declare spir_func i32 @_Z10atomic_decPU3AS1Vj(i32 addrspace(1)*)
declare spir_func i32 @_Z10atomic_decPU3AS3Vj(i32 addrspace(3)*)
declare spir_func i32 @_Z10atomic_decPU3AS1Vi(i32 addrspace(1)*)
declare spir_func i32 @_Z10atomic_decPU3AS3Vi(i32 addrspace(3)*)
declare spir_func i32 @_Z8atom_decPU3AS1Vj(i32 addrspace(1)*)
declare spir_func i32 @_Z8atom_decPU3AS3Vj(i32 addrspace(3)*)
declare spir_func i32 @_Z8atom_decPU3AS1Vi(i32 addrspace(1)*)
declare spir_func i32 @_Z8atom_decPU3AS3Vi(i32 addrspace(3)*)
declare spir_func i32 @_Z14atomic_cmpxchgPU3AS1Vjjj(i32 addrspace(1)*, i32, i32)
declare spir_func i32 @_Z14atomic_cmpxchgPU3AS3Vjjj(i32 addrspace(3)*, i32, i32)
declare spir_func i32 @_Z14atomic_cmpxchgPU3AS1Viii(i32 addrspace(1)*, i32, i32)
declare spir_func i32 @_Z14atomic_cmpxchgPU3AS3Viii(i32 addrspace(3)*, i32, i32)
declare spir_func i32 @_Z12atom_cmpxchgPU3AS1Vjjj(i32 addrspace(1)*, i32, i32)
declare spir_func i32 @_Z12atom_cmpxchgPU3AS3Vjjj(i32 addrspace(3)*, i32, i32)
declare spir_func i32 @_Z12atom_cmpxchgPU3AS1Viii(i32 addrspace(1)*, i32, i32)
declare spir_func i32 @_Z12atom_cmpxchgPU3AS3Viii(i32 addrspace(3)*, i32, i32)


; CHECK: call i32 @_Z8spirv.op.232.PU3AS1jjj(i32 232, i32 addrspace(1)* %gu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS3jjj(i32 232, i32 addrspace(3)* %lu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS1jjj(i32 232, i32 addrspace(1)* %gs, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS3jjj(i32 232, i32 addrspace(3)* %ls, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS1jjj(i32 232, i32 addrspace(1)* %gu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS3jjj(i32 232, i32 addrspace(3)* %lu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS1jjj(i32 232, i32 addrspace(1)* %gs, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.232.PU3AS3jjj(i32 232, i32 addrspace(3)* %ls, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS1jjj(i32 233, i32 addrspace(1)* %gu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS3jjj(i32 233, i32 addrspace(3)* %lu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS1jjj(i32 233, i32 addrspace(1)* %gs, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS3jjj(i32 233, i32 addrspace(3)* %ls, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS1jjj(i32 233, i32 addrspace(1)* %gu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS3jjj(i32 233, i32 addrspace(3)* %lu, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS1jjj(i32 233, i32 addrspace(1)* %gs, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.233.PU3AS3jjj(i32 233, i32 addrspace(3)* %ls, i32 1, i32 80)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS1jjjjjj(i32 230, i32 addrspace(1)* %gu, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS3jjjjjj(i32 230, i32 addrspace(3)* %lu, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS1jjjjjj(i32 230, i32 addrspace(1)* %gs, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS3jjjjjj(i32 230, i32 addrspace(3)* %ls, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS1jjjjjj(i32 230, i32 addrspace(1)* %gu, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS3jjjjjj(i32 230, i32 addrspace(3)* %lu, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS1jjjjjj(i32 230, i32 addrspace(1)* %gs, i32 1, i32 80, i32 80, i32 42, i32 7)
; CHECK: call i32 @_Z8spirv.op.230.PU3AS3jjjjjj(i32 230, i32 addrspace(3)* %ls, i32 1, i32 80, i32 80, i32 42, i32 7)

